<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * 获取指定时间内的每小时开始时间戳和结束时间戳
 * @return <Array>
 */
function getHourCount($time_stamp=null, $mod='+',$len=12){
    $time   = time();
    if(null != $time_stamp && $mod =='+'){
        $time   = $time + $time_stamp;
    }
    if(null != $time_stamp && $mod =='-'){
        $time   = $time - $time_stamp;
    }
    
    $hour   = strtotime(date('Y-m-d H:00:00',$time));
    $arr    = array();
    for($i=$len;$i>0;$i--) {
        $j      = $i-1;
        $start  = $hour;
        $hour   = $hour + 3600;
        $arr[$j]    = array('start' =>$start, 'end'=>$hour);
    }
    return $arr;
}

/**
 * 获取指定时间内的每一天开始时间戳和结束时间戳
 * @return <Array>
 */
function getMonthCount($time_stamp=null, $mod='+', $len=30){
    $time   = time();
    if(null != $time_stamp && $mod =='+'){
        $time   = $time + $time_stamp;
    }
    if(null != $time_stamp && $mod =='-'){
        $time   = $time - $time_stamp;
    }

    $hour   = strtotime(date('Y-m-d 00:00:00',$time));
    $arr    = array();
    for($i=$len;$i>0;$i--) {
        $j      = $i-1;
        $start  = date('Ymd',$hour);
        $hour   = $hour + 3600 * 24;
        $arr[$j]    = array('start' =>$start);
    }
    return $arr;
}
?>
